<?php
/**
 * Maincategoryadmin_Data_Deletemaincategory
 * delete main category
 * @author Adrian Stolarski
 */
class Maincategoryadmin_Data_Deletemaincategory implements Maincategoryadmin_Data_Mainable, 
        Maincategoryadmin_Data_Preparable, Maincategoryadmin_Data_Redirectable{
    
    /**
     *
     * @var type $redirect_action
     * redirect action handler
     */
    public $redirect_action;
    /**
     *
     * @var type $database
     * database handler
     */
    public $database;
    /**
     *
     * @var type $database_query
     * 
     * database query handler
     */
    public $database_query;
    
    /**
     * constructor()
     */
    public function __construct() {
        $this->database = new Core_Driver_MysqlImproved;
    }
    
    /**
     * main()
     * delete main category
     * 
     * @param array $variables
     */
    public function main(array $variables = null) {
        $this->database->connect();
        foreach($variables as $key => $value){
            $variables[$key] = $this->database->escape($value);
        }
        //var_dump($variables);
        //die();
        $this->prepare_query($variables);
        $this->database->prepare($this->database_query);
        //echo $this->database_query;
        //die();
        $this->database->query();
        $this->database->dataOperations();
        $this->redirect_action($variables);
    }
    
    /**
     * preapre_query()
     * prepare database query
     * @param array $variables
     */
    public function prepare_query(array $variables = null) {
        //var_dump($variables);
        //die();
       $this->database_query = "DELETE FROM page_main_category WHERE main_category_name='".$variables['main_category_name']."';"; 
    }
    
    /**
     * redirect_action()
     * redirect to main category list
     * 
     * @param array $variables
     */
    public function redirect_action(array $variables = null) {
        $this->redirect_action = new Maincategoryadmin_Data_Maincateogrieslistredirect;
        $this->redirect_action->main($variables);
    }

}
